import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:test01/okhttp_test/pojo/userinfor_pojo.dart';
import 'package:test01/okhttp_test/util/request_http.dart';

/*
*
*
* ”设置“--------黑名单
*
* */
class BlacklistPage extends StatefulWidget {
  const BlacklistPage({Key key}) : super(key: key);

  @override
  _BlacklistPageState createState() => _BlacklistPageState();
}

class _BlacklistPageState extends State<BlacklistPage> {
  //创建list对象
  List<UserBlacklist> userBlackList=[];



  @override
  void initState() {
    //初始化黑名单接口
    getUserBlackList();
    super.initState();
  }

  ///调用黑名单接口
  getUserBlackList()async{
    userBlackList=await getUserBlacklist(interface:"/appuser/web/black/queryList");
  }


  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        centerTitle: true,
        leading: IconButton(
          icon: Icon(Icons.arrow_back_ios, color: Colors.black),
          onPressed: () {
            ///界面返回
            Navigator.of(context).pop();
            print("返回");
          },
        ),
        backgroundColor: Colors.white,
        elevation: 1,
        title: Text(
          "黑名单",
          style: TextStyle(fontSize: 18, color: Color.fromRGBO(17, 17, 17, 1)),
        ),
      ),
      body: userBlackList.isEmpty?Container(color: Colors.white,):ListView.builder(
        itemBuilder: (BuildContext context, int index) {
          return userItem(index);
        },
        itemCount : userBlackList.length,
      ),
    );
  }

  ///黑名单用户--item
  Widget userItem(int i){
    return Container(
      height: 48,
      width: MediaQuery.of(context).size.width - 32,
      margin: EdgeInsets.only(left: 16,top: 10,right: 16),
      child: Row(
        children: <Widget>[
          //用户头像
          userPicture(i),
          //用户昵称
          userName(i),
          Spacer(),
          //移除
          deleteButton(),
        ],
      ),
    );
  }

  ///用户头像
  Widget userPicture(int i) {
    return ClipOval(
      child: Image.asset(
        userBlackList[i].avatarUri,
        height: 38,
        width: 38,
        fit: BoxFit.cover,
      ),
    );
  }

  ///用户昵称
  Widget userName(i) {
    return Container(
      width: MediaQuery.of(context).size.width - 66-56-16,
      margin: EdgeInsets.only(left: 12),
      child: Text(
        userBlackList[i].nickName,
        style: TextStyle(
          fontSize: 15,
          color: Color.fromRGBO(17, 17, 17, 1),
        ),
        maxLines: 1,
        overflow: TextOverflow.ellipsis,
      ),
    );
  }

  ///移除
  Widget deleteButton() {
    return GestureDetector(
      onTap: () {
        print("----------------移除---------------");
      },
      child: Container(
        height: 24,
        alignment: Alignment.center,
        width: MediaQuery.of(context).size.width - 16 - 303,
        decoration: BoxDecoration(
          border: Border.all(color: Color.fromRGBO(255, 64, 89, 1), width: 0.5),
          borderRadius: BorderRadius.circular(14),
        ),
        child: Text(
          "移除",
          style: TextStyle(fontSize: 12, color: Color.fromRGBO(255, 64, 89, 1)),
        ),
      ),
    );
  }
}
